package com.ganxiang.ximenhong.view;

import android.content.Context;
import android.content.Intent;
import android.util.AttributeSet;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.LinearLayout;

import com.ganxiang.ximenhong.R;
import com.ganxiang.ximenhong.activity.GoodsDetailActivity;
import com.ganxiang.ximenhong.widght.StaticGridView;

import org.json.JSONArray;

/**
 * Created by Administrator on 2016/9/13 0013.
 */
public class GoodsListGv extends LinearLayout{

    private Context mContext;
    private JSONArray mJsonArray;
    private View mView;
    private StaticGridView mGv;
    private GoodsListGvAdapter mAdapter;

    public GoodsListGv(Context context) {
       this(context ,null);
    }

    public GoodsListGv(Context context, AttributeSet attrs) {
        this(context, attrs ,0);
    }

    public GoodsListGv(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        mContext = context;
        mView = View.inflate(context, R.layout.view_goodslist,null);
        this.addView(mView);
        mGv = (StaticGridView) mView.findViewById(R.id.gv);
        mAdapter = new GoodsListGvAdapter();
        mGv.setAdapter(mAdapter);
        mGv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                Intent intent = new Intent(mContext, GoodsDetailActivity.class);
                mContext.startActivity(intent);
            }
        });
    }

    public void setJsonArray(JSONArray jsonArray) {
        this.mJsonArray = jsonArray;
    }

    class GoodsListGvAdapter extends BaseAdapter{

        @Override
        public int getCount() {
            return 10;
        }

        @Override
        public Object getItem(int i) {
            return null;
        }

        @Override
        public long getItemId(int i) {
            return 0;
        }

        @Override
        public View getView(int i, View view, ViewGroup viewGroup) {
            if(view == null ){
                view = View.inflate(mContext, R.layout.item_goods,null);
            }
            return view;
        }
    }
}
